package core.proto.annotation;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.mapviewer.GeoPosition;

import core.proto.annotation.AnnotationModel.AnnotationLocation;
import core.util.logging.constants.Location;
import static app.constants.CollabVizConstants.*;

/**
 * Wrapper class that contains the model and the view/control components of an annotation. 
 * @author Wei 
 *
 */
public class Annotation {

	AnnotationModel model;
	AnnotationUI view;

	public AnnotationModel getModel() {
		return model;
	}

	public AnnotationUI getView() {
		return view;
	}

	public static boolean shouldDeleteAnnotationWith (String text) {
		return text.trim().equals("");
	}

	/**
	 * Create annotation from saved file. 
	 * @param savedLine
	 */
	public Annotation(String savedLine) {
		this(savedLine.split(ANNOTATION_DELIMITER));
	}

	public Annotation(AnnotationModel model, AnnotationUI ui, boolean isLoadingFromDisk) {
		this.model = model;
		this.view = ui;
		if (! isLoadingFromDisk) {
			AnnotationManager.addAnnotation(model.docKey, this);
		}
	}

	private Annotation(String[] tokens){
		AnnotationLocation loc = AnnotationLocation.valueOf(tokens[0]);
		try {
			if (loc == AnnotationLocation.TIMELINE){
				model = new TimelineAnnotationModel(tokens);
				view = new TimelineAnnotationUI(model);
			} else if (loc == AnnotationLocation.DOC) {
				model = new DocAnnotationModel(tokens);
				view = new DocAnnotationUI(model);
			} else if (loc == AnnotationLocation.MAP) {
				model = new MapAnnotationModel(tokens);
				view = new MapAnnotationUI(model);
			} else {
				throw new Error("Unrecognized annotation location " + loc);
			}
		} catch (CannotAddAnnotationException c) {
		}
	}


	/**
	 * Saving. 
	 * @return
	 */
	public String toSerializeString(){
		return model.toSaveString();
	}
}
